export const timeOpts = (selectedTime, yearsCount) => {

  const dateObj = selectedTime ? new Date(selectedTime) : new Date()
  let selectedYear = dateObj.getFullYear()
  let selectedMonth = dateObj.getMonth() + 1

  const currDateObj = new Date()
  let currentYear = currDateObj.getFullYear()
  let currentMonth = currDateObj.getMonth() + 1

  let year = currentYear
  yearsCount = yearsCount || 3

  const monthCount = 12
  const title = selectedTime
  && selectedYear + '' + selectedMonth !== currentYear + '' + currentMonth
    ? selectedYear + '年' + selectedMonth + '月' : '本月'

  let timeOpts = {
    title: title,
    class: 'txt-center',
    value: year,
    checked: selectedYear,
    name: 'year',
    options: []
  }
  for (let i=0; i < yearsCount; i++) {
    let yearOption = {
      text: year + '年',
      checked: selectedMonth,
      name: 'month',
      value: year,
      options: []
    }
    for (let j=1; j <= monthCount; j++) {
      const monthOption = {
        text: year === currentYear && j === currentMonth
          ? j + '月(本月)' : j + '月' ,
        value: j
      }
      yearOption.options.push(monthOption)
    }
    timeOpts.options.push(yearOption)
    year --
  }

  return timeOpts
}
